package leetcode.part2;

import org.junit.Test;

/**
 * 6. Z 字形变换
 */
public class S6 {
    public String convert(String s, int numRows) {
        if (numRows==1) return s;
        StringBuilder[] builders = new StringBuilder[numRows];
        for (int i = 0; i < builders.length; i++) {
            builders[i] = new StringBuilder();
        }
        int len = s.length();
        int index = 0;
        int i = 0;
        int border = numRows - 1;
        boolean riseOrDown=true;

        while (index < len) {
            while (i<border&&index<len){
                builders[i].append(s.charAt(index++));
                i++;
            }
            while (i>0&&index<len){
                builders[i].append(s.charAt(index++));
                i--;
            }

        }
        StringBuilder res = new StringBuilder();
        for (StringBuilder builder : builders) {
            res.append(builder);
        }
        return res.toString();
    }

    @Test
    public void test() {
        String s = "A";
        int numRows = 1;
        System.out.println(convert(s, numRows));
    }
}
